﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

public partial class _Default : System.Web.UI.Page {
    private const string DataFolderName = "~/Templates/";
    private const string HandlerFormatString = "{0}/transform.{1}.axd";

    protected void Page_Init(object sender, EventArgs e) {
        UriBuilder url = new UriBuilder(Request.Url);
        url.Query = string.Empty;
        url.Fragment = string.Empty;
        url.Path = Request.ApplicationPath;
        string baseUrl = url.ToString().TrimEnd('/');

        foreach (string folderName in Directory.GetDirectories(Server.MapPath(DataFolderName))) {
            string templateName = Path.GetFileNameWithoutExtension(folderName);
            string iframeUrl = string.Format(HandlerFormatString, baseUrl, templateName.ToLower());
            this.DropDownListTemplate.Items.Add(new ListItem(templateName, iframeUrl));
        }
    }

    protected void Page_Load(object sender, EventArgs e) {
        this.LiteralLive.Text = string.Format(this.LiteralLive.Text, this.TextBoxW.Text, this.TextBoxH.Text, this.DropDownListTemplate.SelectedValue);
        this.LiteralCode.Text = string.Format(this.LiteralCode.Text, this.TextBoxW.Text, this.TextBoxH.Text, this.DropDownListTemplate.SelectedValue);
    }

}
